"""add_system_integration_extend

Revision ID: 010_system_integration_extend
Revises: 009_api_token_money_extend
Create Date: 2025-03-31 21:36:03.818117

"""
from alembic import op
from models import db, types
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '010_system_integration_extend'
down_revision = '009_api_token_money_extend'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)
    tables = inspector.get_table_names()
    
    if 'system_integration_extend' not in tables:
        op.create_table('system_integration_extend',
        sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
        sa.Column('classify', sa.Integer(), server_default=sa.text('1'), nullable=False),
        sa.Column('status', sa.Boolean(), server_default=sa.text('false'), nullable=False),
        sa.Column('corp_id', sa.String(length=120), nullable=True),
        sa.Column('agent_id', sa.String(length=120), nullable=True),
        sa.Column('app_key', sa.String(length=120), nullable=True),
        sa.Column('app_secret', sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint('id', name='system_integration_joins_pkey')
        )
        with op.batch_alter_table('system_integration_extend', schema=None) as batch_op:
            batch_op.create_index('system_integration_joins_classify_idx', ['classify'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('system_integration_extend', schema=None) as batch_op:
        batch_op.drop_index('system_integration_joins_classify_idx')

    op.drop_table('system_integration_extend')
    # ### end Alembic commands ###
